/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: Hochschule Heilbronn
 * License Type: Academic
 */
package de.hhn.pmt.tour.u6;

import org.orm.*;
import org.hibernate.Query;
import org.hibernate.LockMode;
import java.util.List;

public class EventDAO {
	public static Event loadEventByORMID(String bezeichnung)
			throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return loadEventByORMID(session, bezeichnung);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Event getEventByORMID(String bezeichnung)
			throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return getEventByORMID(session, bezeichnung);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Event loadEventByORMID(String bezeichnung,
			org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return loadEventByORMID(session, bezeichnung, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Event getEventByORMID(String bezeichnung,
			org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return getEventByORMID(session, bezeichnung, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Event loadEventByORMID(PersistentSession session,
			String bezeichnung) throws PersistentException {
		try {
			return (Event) session.load(de.hhn.pmt.tour.u6.Event.class,
					bezeichnung);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Event getEventByORMID(PersistentSession session,
			String bezeichnung) throws PersistentException {
		try {
			return (Event) session.get(de.hhn.pmt.tour.u6.Event.class,
					bezeichnung);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Event loadEventByORMID(PersistentSession session,
			String bezeichnung, org.hibernate.LockMode lockMode)
			throws PersistentException {
		try {
			return (Event) session.load(de.hhn.pmt.tour.u6.Event.class,
					bezeichnung, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Event getEventByORMID(PersistentSession session,
			String bezeichnung, org.hibernate.LockMode lockMode)
			throws PersistentException {
		try {
			return (Event) session.get(de.hhn.pmt.tour.u6.Event.class,
					bezeichnung, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static List queryEvent(String condition, String orderBy)
			throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return queryEvent(session, condition, orderBy);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static List queryEvent(String condition, String orderBy,
			org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return queryEvent(session, condition, orderBy, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Event[] listEventByQuery(String condition, String orderBy)
			throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return listEventByQuery(session, condition, orderBy);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Event[] listEventByQuery(String condition, String orderBy,
			org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return listEventByQuery(session, condition, orderBy, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static List queryEvent(PersistentSession session, String condition,
			String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer(
				"From de.hhn.pmt.tour.u6.Event as Event");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.list();
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static List queryEvent(PersistentSession session, String condition,
			String orderBy, org.hibernate.LockMode lockMode)
			throws PersistentException {
		StringBuffer sb = new StringBuffer(
				"From de.hhn.pmt.tour.u6.Event as Event");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("Event", lockMode);
			return query.list();
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Event[] listEventByQuery(PersistentSession session,
			String condition, String orderBy) throws PersistentException {
		try {
			List list = queryEvent(session, condition, orderBy);
			return (Event[]) list.toArray(new Event[list.size()]);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Event[] listEventByQuery(PersistentSession session,
			String condition, String orderBy, org.hibernate.LockMode lockMode)
			throws PersistentException {
		try {
			List list = queryEvent(session, condition, orderBy, lockMode);
			return (Event[]) list.toArray(new Event[list.size()]);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Event loadEventByQuery(String condition, String orderBy)
			throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return loadEventByQuery(session, condition, orderBy);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Event loadEventByQuery(String condition, String orderBy,
			org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return loadEventByQuery(session, condition, orderBy, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Event loadEventByQuery(PersistentSession session,
			String condition, String orderBy) throws PersistentException {
		Event[] events = listEventByQuery(session, condition, orderBy);
		if (events != null && events.length > 0)
			return events[0];
		else
			return null;
	}

	public static Event loadEventByQuery(PersistentSession session,
			String condition, String orderBy, org.hibernate.LockMode lockMode)
			throws PersistentException {
		Event[] events = listEventByQuery(session, condition, orderBy, lockMode);
		if (events != null && events.length > 0)
			return events[0];
		else
			return null;
	}

	public static java.util.Iterator iterateEventByQuery(String condition,
			String orderBy) throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return iterateEventByQuery(session, condition, orderBy);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static java.util.Iterator iterateEventByQuery(String condition,
			String orderBy, org.hibernate.LockMode lockMode)
			throws PersistentException {
		try {
			PersistentSession session = de.hhn.pmt.tour.u6.LNdMPersistentManager
					.instance().getSession();
			return iterateEventByQuery(session, condition, orderBy, lockMode);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static java.util.Iterator iterateEventByQuery(
			PersistentSession session, String condition, String orderBy)
			throws PersistentException {
		StringBuffer sb = new StringBuffer(
				"From de.hhn.pmt.tour.u6.Event as Event");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static java.util.Iterator iterateEventByQuery(
			PersistentSession session, String condition, String orderBy,
			org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer(
				"From de.hhn.pmt.tour.u6.Event as Event");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("Event", lockMode);
			return query.iterate();
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static Event createEvent() {
		return new de.hhn.pmt.tour.u6.Event();
	}

	public static boolean save(de.hhn.pmt.tour.u6.Event event)
			throws PersistentException {
		try {
			de.hhn.pmt.tour.u6.LNdMPersistentManager.instance().saveObject(
					event);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static boolean delete(de.hhn.pmt.tour.u6.Event event)
			throws PersistentException {
		try {
			de.hhn.pmt.tour.u6.LNdMPersistentManager.instance().deleteObject(
					event);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static boolean deleteAndDissociate(de.hhn.pmt.tour.u6.Event event)
			throws PersistentException {
		try {
			if (event.getLocation() != null) {
				event.getLocation().event.remove(event);
			}

			return delete(event);
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static boolean deleteAndDissociate(de.hhn.pmt.tour.u6.Event event,
			org.orm.PersistentSession session) throws PersistentException {
		try {
			if (event.getLocation() != null) {
				event.getLocation().event.remove(event);
			}

			try {
				session.delete(event);
				return true;
			} catch (Exception e) {
				return false;
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static boolean refresh(de.hhn.pmt.tour.u6.Event event)
			throws PersistentException {
		try {
			de.hhn.pmt.tour.u6.LNdMPersistentManager.instance().getSession()
					.refresh(event);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

	public static boolean evict(de.hhn.pmt.tour.u6.Event event)
			throws PersistentException {
		try {
			de.hhn.pmt.tour.u6.LNdMPersistentManager.instance().getSession()
					.evict(event);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}

}
